#include "SceneSelectRole.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "deprecated/CCDeprecated.h"
#include "ui/UIHelper.h"
#include "base/CCConsole.h"

#include "GLGlobalProtocol.h"
#include "logic/LogicData.h"
#include "logic/LLogicLogin.h"

USING_NS_CC;
using namespace ui;

CSceneSelectRole::CSceneSelectRole(void) : m_SelectRoleNode(nullptr)
{
}


CSceneSelectRole::~CSceneSelectRole(void)
{
}

bool CSceneSelectRole::init() {
	// 1. super init first
    if ( !CSceneBase::init() )
    {
        return false;
    }

	m_SelectRoleNode = CSLoader::createNode("SelectRole.csb");
	m_SelectView = (cocos2d::ui::PageView*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_SelectRoleNode, 416);
	ui::Button* tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_SelectRoleNode, 430);
	tLoginB->addTouchEventListener(this, toucheventselector(CSceneSelectRole::onRight));
	tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_SelectRoleNode, 429);
	tLoginB->addTouchEventListener(this, toucheventselector(CSceneSelectRole::onLeft));
	tLoginB = (ui::Button*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_SelectRoleNode, 426);
	tLoginB->addTouchEventListener(this, toucheventselector(CSceneSelectRole::onSelect));

	addChild(m_SelectRoleNode);
    return true;
}

void CSceneSelectRole::onRight(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type) {
	case cocos2d::ui::TOUCH_EVENT_ENDED: {
		m_SelectView->scrollToPage(m_SelectView->getCurPageIndex() + 1);
		} break;
	}
}

void CSceneSelectRole::onLeft(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type) {
	case cocos2d::ui::TOUCH_EVENT_ENDED: {
		m_SelectView->scrollToPage(m_SelectView->getCurPageIndex() - 1);
		} break;
	}
}

void CSceneSelectRole::onSelect(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type) {
	switch (type) {
	case cocos2d::ui::TOUCH_EVENT_ENDED: {
		ssize_t tIndex = m_SelectView->getCurPageIndex();
		switch (tIndex)
		{
		case ARMZs:
			tIndex = AnimalPersonZs;
			break;
		case ARMGjs:
			tIndex = AnimalPersonGjs;
			break;
		case ARMYs:
			tIndex = AnimalPersonYs;
			break;
		case ARMFs:
			tIndex = AnimalPersonFs;
			break;
		case ARMFys:
			tIndex = AnimalPersonFys;
			break;
		default:
			CCLOG("error:%d", tIndex);
			assert(false);
			break;
		}
		char nick[50] = {0};
		sprintf(nick, "test_%u", time(0));
		CTLLogicLogin tLogin;
		tLogin.CreateRole(tIndex, nick);
		} break;
	}
}
